package com.acwing.partition11;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/3/7 9:19
 */
public class AC1078旅游规划 {

    private static final int N = 200010, INF = 0x3f3f3f3f;
    private static int[] h = new int[N], e = new int[2 * N], ne = new int[2 * N];
    //dist1[i]记录节点i向下的最长路径；dist2[i]记录节点i向下的次长路径；dist3[i]记录节点i向上走的最长路径；path[i]记录在向下找最长路径时，节点i经过的点
    private static int[] dist1 = new int[N], dist2 = new int[N], dist3 = new int[N], path = new int[N];
    private static int n, idx = 0, maxd = -INF;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        Arrays.fill(h, -1);
        for (int i = 0; i < n - 1; i++) {
            String[] ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            add(a, b);
            add(b, a);
        }
        dfs1(0, -1);
        dfs2(0, -1);
        for (int i = 0; i < n; i++) {
            //从每个节点的三个路径找出最长的两个路径
            int[] arr = new int[]{dist1[i], dist2[i], dist3[i]};
            Arrays.sort(arr);
            if (arr[2] + arr[1] == maxd) {
                writer.write(i + "\n");
            }
        }
        writer.flush();
    }

    private static void dfs1(int u, int parent) {
        dist1[u] = dist2[u] = 0;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (v == parent) continue;
            dfs1(v, u);
            if (dist1[v] + 1 >= dist1[u]) {
                dist2[u] = dist1[u];
                dist1[u] = dist1[v] + 1;
                path[u] = v;
            } else if (dist1[v] + 1 > dist2[u]) {
                dist2[u] = dist1[v] + 1;
            }
        }
        maxd = Math.max(maxd, dist1[u] + dist2[u]);
    }

    private static void dfs2(int u, int parent) {
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (v == parent) continue;
            //使用父节点来计算子节点，如果父节点的最长路径是向下走且经过了子节点的最长路径，那就使用子节点的次长路径
            dist3[v] = dist3[u] + 1;
            if (path[u] == v) dist3[v] = Math.max(dist3[v], dist2[u] + 1);
            else dist3[v] = Math.max(dist3[v], dist1[u] + 1);
            dfs2(v, u);
        }
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
